package com.ysmygx.service.impl;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson2.JSON;
import com.ysmygx.config.RequestBodyFactory;
import com.ysmygx.entity.*;
import com.ysmygx.service.BankService;
import com.ysmygx.service.EnvelopeService;
import com.ysmygx.service.SignService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Log4j2
@Service
public class BankServiceImpl implements BankService {
    @Value("${pay.query-balance-url}")
    private String queryBalanceUrl;



    @Value("${pay.bank-sn}")
    private String bankSn;

    @Autowired
    private RequestBodyFactory requestBodyFactory;

    @Autowired
    private SignService signService;

    @Autowired
    private EnvelopeService envelopeService;

    @Override
    public String queryBalance(String body) {
        log.info(body);
        HttpResponse response = HttpRequest.post(queryBalanceUrl)
                .header(Header.CONTENT_TYPE, "application/json")
                .body(body)
                .execute();

        BankServiceResp bankServiceResp = null;
        if (response.isOk()){
            String respBody = response.body();
            bankServiceResp = JSON.parseObject(respBody, BankServiceResp.class);
        }
        log.info(bankServiceResp);
        return bankServiceResp.getData();
    }

    @Override
    public String singleTransfer(SingleTransferReq singleTransferReq) {
        log.info(singleTransferReq);
        RequestBody<SingleTransferReq> requestBody = requestBodyFactory.build(singleTransferReq);
//        String encResult = doService(requestBody, singleTransferUrl);

        return null;

    }

    @Override
    public void queryTransferStatus() {

    }

    @Override
    public void queryAccountDetail() {

    }

    @Override
    public String doService(RequestBody body, String url) {
        return null;
    }

}
